package com.mhuang.common.handler;

import java.util.concurrent.TimeUnit;

import com.mhuang.client.NettyClientHandler;
import com.mhuang.common.coder.ClientDecoder;
import com.mhuang.common.coder.ClientEncoder;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.timeout.IdleStateHandler;

public class ClientChannelInitializerHandler extends ChannelInitializer<SocketChannel>{

	private static final ClientEncoder encoder = new ClientEncoder();
	
	public ClientChannelInitializerHandler(){
		super();
	}
	@Override
	protected void initChannel(SocketChannel ch) throws Exception {
		ChannelPipeline pipeline = ch.pipeline();  
		pipeline.addLast(new IdleStateHandler(30,10,0,TimeUnit.SECONDS));
		pipeline.addLast(encoder);
		pipeline.addLast(new ClientDecoder());
		pipeline.addLast(new NettyClientHandler());
	}
}
